package com.forum.service.Impl;

import com.forum.dao.EvaluateDaoMapper;
import com.forum.dao.MessageDaoMapper;
import com.forum.pojo.Message;
import com.forum.pojo.Module;
import com.forum.pojo.Evaluate;
import com.forum.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("MessageService")
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageDaoMapper messageDaoMapper;

    @Autowired
    private EvaluateDaoMapper evaluateDaoMapper;

    @Override
    public int addMessager(Message message) {
        return messageDaoMapper.saveMessage(message);
    }

    public MessageDaoMapper getMessageDaoMapper() {
        return messageDaoMapper;
    }

    public void setMessageDaoMapper(MessageDaoMapper messageDaoMapper) {
        this.messageDaoMapper = messageDaoMapper;
    }

    @Override
    public Message findMessageById(String messageID) {
        Message message = new Message();
        message.setMessageID(messageID);
        if(messageDaoMapper.findMessage(message).size()>0)
            return messageDaoMapper.findMessage(message).get(0);
        return null;
    }

    @Override
    public List<Message> findMessageByModuleName(String moduleName) {
        Message message = new Message();
        message.setAuditSatus("通过");
        message.setModuleName(moduleName);
        return messageDaoMapper.findMessage(message);
    }

    @Override
    public List<Message> findMessageByMessageName(String messageName) {
        Message message = new Message();
        message.setAuditSatus("通过");
        message.setMessageName(messageName);
        return messageDaoMapper.findMessage(message);
    }

    @Override
    public List<Message> findMessageByUserID(String userID) {
        Message message = new Message();
        message.setUserID(userID);
        return messageDaoMapper.findMessage(message);
    }


    @Override
    public List<Message> findAllMessage() {
        return messageDaoMapper.findMessage(new Message());
    }

    @Override
    public int deleteMessage(String messageID) {
        return messageDaoMapper.deleteMessage(messageID);
    }

    @Override
    public List<Evaluate> findEvaluate(String messageID) {
        return messageDaoMapper.findEvaluate(messageID);
    }

    @Override
    public List<Module> Allmodule() {
        return messageDaoMapper.Allmodule();
    }

    @Override
    public int updateMessage(String messageContent, String moduleName ,String messageID) {
        Message message = new Message();
        message.setMessageContent(messageContent);
        message.setModuleName(moduleName);
        message.setMessageID(messageID);
        return messageDaoMapper.updateMessage(message);
    }

    @Override
    public int addEvaluate(String messageID,String userID,String comments) {
        Evaluate evaluate1 = new Evaluate();
        evaluate1.setComments(comments);
        evaluate1.setUserID(userID);
        evaluate1.setMessageID(messageID);
        return evaluateDaoMapper.saveEvaluate(evaluate1);
    }
}
